//
//  UnitToolCommonView.m
//  baojia
//
//  Created by Baojia-LC on 14-9-23.
//  Copyright (c) 2014年 com.baojia.www. All rights reserved.
//

#import "UnitToolCommonView.h"
@implementation UnitToolCommonView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}


+(UIView*)viewWithLabel:(NSString*)text image:(NSString*)image{
    
    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
    
    UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(4, (view.height-20)/2, 18, 18)];
    imageView.image = [UIImage imageNamed:image];
    [view addSubview:imageView];
    
    CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:14.0]];
    UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(imageView.right+5, (view.height-24)/2, size.width, 24)];
    label.textAlignment = NSTextAlignmentLeft;
    label.font = [UIFont systemFontOfSize:14.0];
    label.tag = 1000;
    label.textColor = [UIColor colorWithRed:0.28f green:0.27f blue:0.28f alpha:1.00f];
    label.text = text;
    [view addSubview:label];
    
    return view;
}

+(UIView*)viewWithLabel:(NSString*)text image:(NSString*)image font:(UIFont*)font{
    
    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
    
    UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(4, (view.height-15)/2, 15, 15)];
    imageView.image = [UIImage imageNamed:image];
    [view addSubview:imageView];
    
    CGSize size = [text sizeWithFont:font];
    UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(imageView.right+5, (view.height-15)/2, size.width, 15)];
    label.textAlignment = NSTextAlignmentLeft;
    label.font = font;
    label.tag = 1000;
    label.textColor = COLOR_RGB(122, 122, 122);
    label.text = text;
    [view addSubview:label];
    
    return view;
}

+(UIScrollView*)scrollviewWithFrame:(CGRect)frame contentSize:(CGSize)size{
    
    UIScrollView* scrollView = [[UIScrollView alloc] initWithFrame:frame];
    scrollView.contentSize = size;
    [scrollView setShowsHorizontalScrollIndicator:NO];
    [scrollView setShowsVerticalScrollIndicator:NO];
    return scrollView;
    
}

+(UIButton*)viewWithButtonWithText:(NSString*)text textColor:(UIColor*)textColor frame:(CGRect)frame{
    UIButton* button = [[UIButton alloc] initWithFrame:frame];
    [button setTitle:text forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:16];
    [button setTitleColor:textColor forState:UIControlStateNormal];
    return button;
}


+(NSString*)substring:(NSString*)subs content:(NSString*)text{
    NSRange range = [text rangeOfString:subs];
    if(range.location != NSNotFound){
        return [text substringToIndex:range.location];
    }
    return @"";
}


+(UITextField*)viewLineTextFeildWithText:(NSString*)placeHolder textColor:(UIColor*)textColor frame:(CGRect)frame font:(UIFont*)font{
    
    UITextField* textFeild = [[UITextField alloc] initWithFrame:frame];
    textFeild.placeholder = placeHolder;
    textFeild.backgroundColor = [UIColor clearColor];
    textFeild.textAlignment = NSTextAlignmentLeft;
    textFeild.font = font;
    textFeild.textColor = textColor;
    
    UIImageView* line = [[UIImageView alloc] initWithFrame:CGRectMake(0, frame.size.height -1, textFeild.width,1)];
    line.backgroundColor = COLOR_RGB(213, 212, 213);
    [textFeild addSubview:line];
    
    return textFeild;
}

+(UIButton*)createLineButtonViewWithFrame:(CGRect)frame title:(NSString*)title titleColor:(UIColor*)textColor font:(UIFont*)font sel:(SEL)selector target:(UIViewController*)vc{
    
    UIButton* button = [[UIButton alloc] initWithFrame:frame];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:textColor forState:UIControlStateNormal];
    button.titleLabel.font = font;
    button.backgroundColor = [UIColor clearColor];
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    //    button.titleEdgeInsets = UIEdgeInsetsMake(0, -180, 0, 0);
    [button addTarget:vc action:selector forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView* line = [[UIImageView alloc] initWithFrame:CGRectMake(0, frame.size.height -1, button.width,1)];
    line.backgroundColor = COLOR_RGB(213, 212, 213);
    [button addSubview:line];
    
    return button;
}

+(UIImageView*)addRedFlotMessagePushDataWithUimageView:(UIView*)supView{
    
    CGFloat bottomOrigX = supView.right - 10;
    CGFloat bottomOrigY = supView.bottom - 10;
    UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(bottomOrigX, bottomOrigY, 10, 10)];
    [imageView setBackgroundColor:[UIColor redColor]];
    return imageView;
}


@end
